#include <stdio.h>
#include <string.h>

/* http://code.google.com/codejam/contest/351101/dashboard#s=p2 */

/* using naive table driven */
char *mapping[] = {
    "0",
    "23456",
    "7",
    "8",
    "9"
};

int main(int argc, char **argv)
{
    if(argc < 2) {
        fprintf(stderr, "provide a message please!\n");
        return -1;
    }

    char *str = argv[1];
    int len = strlen(str);
    int i, j, m_idx, offset, idx, times;
    char last_digit, curr_char, which_digit;
    last_digit = '\0';
    for(i = 0;i < len;i++) {
        curr_char = str[i];
        if(' ' == curr_char) {
            m_idx = 0;
            idx = 0;
            times = 1;
        } else if(curr_char >= 'a' && curr_char <= 'o') {
            m_idx = 1;
            offset = curr_char - 'a';
            idx = offset / 3;
            times = offset % 3 + 1;
        } else if(curr_char > 'o' && curr_char <= 's') {
            m_idx = 2;
            idx = 0;
            times = curr_char - 'p' + 1;
        } else if(curr_char > 's' && curr_char <= 'v') {
            m_idx = 3;
            idx = 0;
            times = curr_char - 't' + 1;
        } else if(curr_char > 'v' && curr_char <= 'z'){
            m_idx = 4;
            idx = 0;
            times = curr_char - 'w' + 1;
        } else {
            continue;
        }

        which_digit = mapping[m_idx][idx];
        if(which_digit == last_digit)
            putchar(' ');
        for(j = 0;j < times;j++)
            putchar(which_digit);
        last_digit = which_digit;
    }
}
